package com.freesaas.merchant.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.freesaas.merchant.service.CreateOrderService;
import com.freesaas.merchant.vo.P00201Request;

/**
 * @author Windy
 * 作为备份，暂时无用
 */
@Controller
public class P004Action {

	private Logger logger = LoggerFactory.getLogger(P004Action.class);

	@Autowired
	private CreateOrderService createOrderService;

	/**
	 * @param p00201Req
	 * @param request
	 *            保存支付订单
	 */
	@RequestMapping(value = "/P00401", method = RequestMethod.POST)
	public ModelAndView P00401(P00201Request p00201Req, HttpServletRequest request) {
		String userAgent = request.getHeader("User-Agent");
		logger.info("浏览器信息：{}", userAgent);
		logger.info("请求IP：{}", request.getRemoteAddr());
		String remoteIp = request.getRemoteAddr();
		String busTyp = null;
		if (userAgent.indexOf("MicroMessenger") > 0) {
			busTyp = "1001";
		} else if (userAgent.indexOf("AlipayClient") > 0 || userAgent.indexOf("AliApp") > 0
				|| userAgent.indexOf("AlipayDefined") > 0) {
			busTyp = "1002";
		}
		Map<String, String> retmap = null;
		try {
			retmap = createOrderService.P00201(p00201Req, remoteIp, busTyp);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		retmap.put("packageStr", retmap.get("package"));
		logger.info("返回数据：{}", retmap);
		return new ModelAndView("pay_ok", retmap);
	}

}
